﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using WebCore_MVC.Data;


namespace WebCore_MVC.Services
{
    public class ServiceContext
    {
        private DbContext _dbContext;

        public DbContext DbContext
        {

           

            get
            {
                if (_dbContext == null)

                    _dbContext = _serviceProvider.GetService<DataContext>();
                    return _dbContext;              
            }
        }

        private readonly IServiceProvider _serviceProvider;
        public ServiceContext(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

      

    }

}

